package com.zmn.plat.services.impl.base.faultphenomenon;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.base.phenomenon.PhenomenonMaintain;
import com.zmn.plat.model.entity.base.phenomenon.PhenomenonMaintainQuery;
import com.zmn.plat.model.vo.base.phenomenon.PhenomenonMaintainVO;
import com.zmn.plat.persistence.interfaces.base.phenomenon.PhenomenonMaintainDao;
import com.zmn.plat.services.interfaces.base.phenomenon.PhenomenonMaintainService;
import org.springframework.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

import com.zmn.common.constant.GlobalConsts;

/**
 * 描述: 故障现象-检修项目接口实现类
 *
 * @author chengguang
 * @since 2021/11/19 10:38
 */
@Slf4j
@Service
public class PhenomenonMaintainServiceImpl implements PhenomenonMaintainService {

    private static final String TAG = "故障现象-检修项目基础服务接口";

    @Resource
    private PhenomenonMaintainDao phenomenonMaintainDao;

    @Override
    public PhenomenonMaintain findById(Integer relateId) {
        if (Objects.isNull(relateId)) {
            log.error("[{}],根据id查询数据relateId为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.findById(relateId);
    }

    @Override
    public List<PhenomenonMaintain> listByIds(List<Integer> relateIds) {
        if (CollectionUtils.isEmpty(relateIds)) {
            log.error("[{}],按条件查询数据,relateIds为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.listByIds(relateIds);
    }

    @Override
    public List<PhenomenonMaintain> listByQuery(PhenomenonMaintainQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.listByQuery(query);
    }

    @Override
    public List<PhenomenonMaintain> listByPhenIds(List<Integer> phenIds) {

        return phenomenonMaintainDao.listByPhenIds(phenIds);
    }

    @Override
    public List<PhenomenonMaintain> listPageByQuery(PhenomenonMaintainQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(phenomenonMaintainDao.countByQuery(query));
        return phenomenonMaintainDao.listPageByQuery(query);
    }

    @Override
    public List<PhenomenonMaintainVO> listMaintainNameAndIdByphenIds(List<Integer> phenIds) {
        return phenomenonMaintainDao.listMaintainNameAndIdByphenIds(phenIds);
    }

    @Override
    public Integer countByQuery(PhenomenonMaintainQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(PhenomenonMaintain phenomenonMaintain) {
        if (Objects.isNull(phenomenonMaintain.getRelateId())) {
            log.error("[{}],根据id修改数据,PhenomenonMaintain为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.updateByKey(phenomenonMaintain);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {
        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        phenomenonMaintainDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public void updateMaintainNameByMaintainId(Integer maintainId,String maintainName) {
        phenomenonMaintainDao.updateMaintainNameByMaintainId(maintainId,maintainName);
    }

    @Override
    public Integer insert(PhenomenonMaintain PhenomenonMaintain) {
        if (Objects.isNull(PhenomenonMaintain)) {
            log.error("[{}],新增数据,PhenomenonMaintain为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.insert(PhenomenonMaintain);
    }

    @Override
    public void insertBatch(List<PhenomenonMaintain> list) {
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        phenomenonMaintainDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Integer relateId) {
        if (Objects.isNull(relateId)) {
            log.error("[{}],根据id删除数据,relateId为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.deleteByKey(relateId);
    }

    @Override
    public Integer deleteByPhenId(Integer phenId) {
        if (Objects.isNull(phenId)) {
            log.error("[{}],根据id删除数据,relateId为null", TAG);
            return null;
        }
        return phenomenonMaintainDao.deleteByPhenId(phenId);
    }

    @Override
    public Integer deleteByMaintainIds(List<Integer> maintainIds) {
        return phenomenonMaintainDao.deleteByMaintainIds(maintainIds);
    }

}